package org.streets.eis.component.grid;


import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.model.IModel;
import org.streets.eis.component.ChangedNotifyType;
import org.streets.eis.component.buttonededit.ButtonedEdit;
import org.streets.eis.component.model.ListItem;

import com.inmethod.grid.column.AbstractColumn;

public abstract class ButtonedEditColumn extends EditableColumn {
	private static final long serialVersionUID = 1L;
	
	private ChangedNotifyType changedNotifyType = ChangedNotifyType.NONE;
	
	@SuppressWarnings("unchecked")	
	public ButtonedEditColumn(String columnId, IModel headerModel, String propertyExpression, String sortProperty) {
		super(columnId, headerModel, propertyExpression, sortProperty);
	}
	
	@SuppressWarnings("unchecked")	
	public ButtonedEditColumn(String columnId, IModel headerModel, String propertyExpression) {
		super(columnId, headerModel, propertyExpression);
	}

	@SuppressWarnings("unchecked")	
	public ButtonedEditColumn(IModel headerModel, String propertyExpression, String sortProperty) {
		super(headerModel, propertyExpression, sortProperty);
	}
	
	@SuppressWarnings("unchecked")	
	public ButtonedEditColumn(IModel headerModel, String propertyExpression) {
		super(headerModel, propertyExpression);
	}	
	
	@SuppressWarnings("unchecked")
	@Override
	protected FormComponent newEditableComponent(String id, final IModel model, IModel rowModel, AbstractColumn column){
		return new ButtonedEdit(id,model){
			private static final long serialVersionUID = 1L;

			@Override
			protected ChangedNotifyType getChangedNotifyType(){
				return ButtonedEditColumn.this.getChangedNotifyType();
			}
			
			@Override
			protected void onButtonClicked(final ButtonedEdit edit,AjaxRequestTarget target) {
				ButtonedEditColumn.this.onButtonClicked(edit,target);
			}
			
			@Override
			protected void onValueChanged(ListItem newValue){
				ButtonedEditColumn.this.onValueChanged(this,newValue);
			}
			
			@Override
			protected void onAjaxValueChanged(ListItem newValue,AjaxRequestTarget target){
				ButtonedEditColumn.this.onAjaxValueChanged(this,newValue,target);
			}
		};
	}
	
	public ChangedNotifyType getChangedNotifyType() {
		return changedNotifyType;
	}

	public void setChangedNotifyType(ChangedNotifyType changedNotifyType) {
		this.changedNotifyType = changedNotifyType;
	}	
	
	protected abstract void onButtonClicked(final ButtonedEdit edit,AjaxRequestTarget target) ;
	
	protected void onValueChanged(ButtonedEdit edit,ListItem newValue){		
	}

	protected void onAjaxValueChanged(ButtonedEdit edit,ListItem newValue,AjaxRequestTarget target){
	}
	
}
